<?php
//Connection statement
require_once('../Connections/cn.php');

// Load the common classes
require_once('../includes/common/KT_common.php');

// Load the tNG classes
require_once('../includes/tng/tNG.inc.php');

// Load the KT_back class
require_once('../includes/nxt/KT_back.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("../");

// Start trigger
$formValidation = new tNG_FormValidation();
$formValidation->addField("codigo_carrera", true, "text", "", "", "", "Please enter a valid value.");
$formValidation->addField("nombre_carrera", true, "text", "", "", "", "Please enter a valid value.");
$formValidation->addField("duracion_carrera", true, "numeric", "", "", "", "Please enter a valid value.");
$formValidation->addField("estado_carrera", true, "", "", "", "", "Please enter a valid value.");
$tNGs->prepareValidation($formValidation);
// End trigger

//start trg_codigo_carrera trigger
//remove this line if you want to edit the code by hand
function trg_codigo_carrera(&$tNG) {
  $tblFldObj = new tNG_CheckUnique($tNG);
  $tblFldObj->setTable("carrera");
  $tblFldObj->setFieldName("codigo_carrera");
  $tblFldObj->setErrorMsg("El codigo de la carrera ya existe");
  return $tblFldObj->Execute();
}
//end trg_codigo_carrera trigger

//start trg_nombre_carrera trigger
//remove this line if you want to edit the code by hand
function trg_nombre_carrera(&$tNG) {
  $tblFldObj = new tNG_CheckUnique($tNG);
  $tblFldObj->setTable("carrera");
  $tblFldObj->setFieldName("codigo_carrera");
  $tblFldObj->setErrorMsg("El nombre de la carrera ya existe");
  return $tblFldObj->Execute();
}
//end trg_nombre_carrera trigger

// Make an insert transaction instance
$ins_carrera = new tNG_multipleInsert($cn);
$tNGs->addTransaction($ins_carrera);
// Register triggers
$ins_carrera->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$ins_carrera->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$ins_carrera->registerTrigger("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.php");
$ins_carrera->registerTrigger("BEFORE", "trg_codigo_carrera", 30);
$ins_carrera->registerTrigger("BEFORE", "trg_nombre_carrera", 30);
// Add columns
$ins_carrera->setTable("carrera");
$ins_carrera->addColumn("codigo_carrera", "STRING_TYPE", "POST", "codigo_carrera");
$ins_carrera->addColumn("nombre_carrera", "STRING_TYPE", "POST", "nombre_carrera");
$ins_carrera->addColumn("duracion_carrera", "NUMERIC_TYPE", "POST", "duracion_carrera");
$ins_carrera->addColumn("estado_carrera", "CHECKBOX_1_0_TYPE", "POST", "estado_carrera", "0");
$ins_carrera->setPrimaryKey("codigo_carrera", "STRING_TYPE");

// Make an update transaction instance
$upd_carrera = new tNG_multipleUpdate($cn);
$tNGs->addTransaction($upd_carrera);
// Register triggers
$upd_carrera->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1");
$upd_carrera->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$upd_carrera->registerTrigger("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.php");
$upd_carrera->registerTrigger("BEFORE", "trg_codigo_carrera", 30);
$upd_carrera->registerTrigger("BEFORE", "trg_nombre_carrera", 30);
// Add columns
$upd_carrera->setTable("carrera");
$upd_carrera->addColumn("codigo_carrera", "STRING_TYPE", "POST", "codigo_carrera");
$upd_carrera->addColumn("nombre_carrera", "STRING_TYPE", "POST", "nombre_carrera");
$upd_carrera->addColumn("duracion_carrera", "NUMERIC_TYPE", "POST", "duracion_carrera");
$upd_carrera->addColumn("estado_carrera", "CHECKBOX_1_0_TYPE", "POST", "estado_carrera");
$upd_carrera->setPrimaryKey("codigo_carrera", "STRING_TYPE", "GET", "codigo_carrera");

// Make an instance of the transaction object
$del_carrera = new tNG_multipleDelete($cn);
$tNGs->addTransaction($del_carrera);
// Register triggers
$del_carrera->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Delete1");
$del_carrera->registerTrigger("END", "Trigger_Default_Redirect", 99, "../includes/nxt/back.php");
// Add columns
$del_carrera->setTable("carrera");
$del_carrera->setPrimaryKey("codigo_carrera", "STRING_TYPE", "GET", "codigo_carrera");

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
$rscarrera = $tNGs->getRecordset("carrera");
$totalRows_rscarrera = $rscarrera->RecordCount();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php //PHP ADODB document - made with PHAkt 3.6.0?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="../includes/common/js/base.js" type="text/javascript"></script>
<script src="../includes/common/js/utility.js" type="text/javascript"></script>
<script src="../includes/skins/style.js" type="text/javascript"></script>
<?php echo $tNGs->displayValidationRules();?>
<script src="../includes/nxt/scripts/form.js" type="text/javascript"></script>
<script src="../includes/nxt/scripts/form.js.php" type="text/javascript"></script>
<script type="text/javascript">
$NXT_FORM_SETTINGS = {
  duplicate_buttons: false,
  show_as_grid: true,
  merge_down_value: true
}
</script>
</head>

<body>
<?php
	echo $tNGs->getErrorMsg();
?>
<div class="KT_tng">
  <h1>
    <?php 
// Show IF Conditional region1 
if (@$_GET['codigo_carrera'] == "") {
?>
      <?php echo NXT_getResource("Insert_FH"); ?>
      <?php 
// else Conditional region1
} else { ?>
      <?php echo NXT_getResource("Update_FH"); ?>
      <?php } 
// endif Conditional region1
?>
    Carrera </h1>
  <div class="KT_tngform">
    <form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
      <?php $cnt1 = 0; ?>
      <?php
  while (!$rscarrera->EOF) { 
?>
        <?php $cnt1++; ?>
        <?php 
// Show IF Conditional region1 
if (@$totalRows_rscarrera > 1) {
?>
          <h2><?php echo NXT_getResource("Record_FH"); ?> <?php echo $cnt1; ?></h2>
          <?php } 
// endif Conditional region1
?>
        <table cellpadding="2" cellspacing="0" class="KT_tngtable">
          <tr>
            <td class="KT_th"><label for="codigo_carrera_<?php echo $cnt1; ?>">Codigo_carrera:</label></td>
            <td><input type="text" name="codigo_carrera_<?php echo $cnt1; ?>" id="codigo_carrera_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($rscarrera->Fields('codigo_carrera')); ?>" size="13" maxlength="13" />
                <?php echo $tNGs->displayFieldHint("codigo_carrera");?> <?php echo $tNGs->displayFieldError("carrera", "codigo_carrera", $cnt1); ?> </td>
          </tr>
          <tr>
            <td class="KT_th"><label for="nombre_carrera_<?php echo $cnt1; ?>">Nombre_carrera:</label></td>
            <td><input type="text" name="nombre_carrera_<?php echo $cnt1; ?>" id="nombre_carrera_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($rscarrera->Fields('nombre_carrera')); ?>" size="32" maxlength="100" />
                <?php echo $tNGs->displayFieldHint("nombre_carrera");?> <?php echo $tNGs->displayFieldError("carrera", "nombre_carrera", $cnt1); ?> </td>
          </tr>
          <tr>
            <td class="KT_th"><label for="duracion_carrera_<?php echo $cnt1; ?>">Duracion_carrera:</label></td>
            <td><input type="text" name="duracion_carrera_<?php echo $cnt1; ?>" id="duracion_carrera_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($rscarrera->Fields('duracion_carrera')); ?>" size="4" />
                <?php echo $tNGs->displayFieldHint("duracion_carrera");?> <?php echo $tNGs->displayFieldError("carrera", "duracion_carrera", $cnt1); ?> </td>
          </tr>
          <tr>
            <td class="KT_th"><label for="estado_carrera_<?php echo $cnt1; ?>">Estado_carrera:</label></td>
            <td><input  <?php if (!(strcmp(KT_escapeAttribute($rscarrera->Fields('estado_carrera')),"1"))) {echo "checked";} ?> type="checkbox" name="estado_carrera_<?php echo $cnt1; ?>" id="estado_carrera_<?php echo $cnt1; ?>" value="1" />
                <?php echo $tNGs->displayFieldError("carrera", "estado_carrera", $cnt1); ?> </td>
          </tr>
        </table>
        <input type="hidden" name="kt_pk_carrera_<?php echo $cnt1; ?>" class="id_field" value="<?php echo KT_escapeAttribute($rscarrera->Fields('kt_pk_carrera')); ?>" />
        <?php
    $rscarrera->MoveNext(); 
  }
?>
      <div class="KT_bottombuttons">
        <div>
          <?php 
      // Show IF Conditional region1 
      if (@$_GET['codigo_carrera'] == "") {
      ?>
            <input type="submit" name="KT_Insert1" id="KT_Insert1" value="<?php echo NXT_getResource("Insert_FB"); ?>" />
            <?php 
      // else Conditional region1
      } else { ?>
            <input type="submit" name="KT_Update1" value="<?php echo NXT_getResource("Update_FB"); ?>" />
            <input type="submit" name="KT_Delete1" value="<?php echo NXT_getResource("Delete_FB"); ?>" onclick="return confirm('<?php echo NXT_getResource("Are you sure?"); ?>');" />
            <?php } 
      // endif Conditional region1
      ?>
          <input type="button" name="KT_Cancel1" value="<?php echo NXT_getResource("Cancel_FB"); ?>" onclick="return UNI_navigateCancel(event, '../includes/nxt/back.php')" />
        </div>
      </div>
    </form>
  </div>
  <br class="clearfixplain" />
</div>
<p>&nbsp;</p>
</body>
</html>
